/*
 * QCursorAdapter.cpp  0.4.0 / Nov 17, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
#include "QCursorAdapter.h"

#include "JNILogger.h"

// QCursorAdapter :: Public Constructor. ---------------------------------------

/*!
 * \brief Constructs new QCursorAdapter object.
 *
 * \param type the type of the cursor
 */
QCursorAdapter::QCursorAdapter(int type)
  : QCursor(CURSOR_SHAPE[rangeCheck(type)])
{
  // empty body
}

// QCursorAdapter :: Public Static Member Function. ----------------------------

/*!
 * \brief Returns Swing type of the cursor.
 *
 * \returns Swing type of the cursor
 */
int QCursorAdapter::cursorType(const QCursor &cursor)
{
  Qt::CursorShape cursorShape = cursor.shape();
  for (int i = 20; --i >= 0;) {
    if (cursorShape == CURSOR_SHAPE[i]) {
      return i;
    }
  }
  return 0;
}

// QCursorAdapter :: Private Static Member Function. ---------------------------

int QCursorAdapter::rangeCheck(int type)
{
  if ((type >= 0) && (type <= 19)) {
    return type;
  } else {
    LOG_WARNING("Cursor type out of the bounds");
    return 0;
  }
}

// QCursorAdapter :: Private Constant Member. ----------------------------------

const Qt::CursorShape QCursorAdapter::CURSOR_SHAPE[] = {
  Qt::ArrowCursor,
  Qt::CrossCursor,
  Qt::IBeamCursor,
  Qt::WaitCursor,
  Qt::SizeBDiagCursor,
  Qt::SizeFDiagCursor,
  Qt::SizeFDiagCursor,
  Qt::SizeBDiagCursor,
  Qt::SizeVerCursor,
  Qt::SizeVerCursor,
  Qt::SizeHorCursor,
  Qt::SizeHorCursor,
  Qt::PointingHandCursor,
  Qt::SizeAllCursor,
  Qt::UpArrowCursor,
  Qt::ForbiddenCursor,
  Qt::WhatsThisCursor,
  Qt::SplitVCursor,
  Qt::SplitHCursor,
  Qt::BlankCursor
};
